<template>
  <div>
    <page-main>
      <el-table :data="dataList" :default-sort="{ prop: 'id', order: 'ascending' }">
        <el-table-column label="姓名" prop="user_name"></el-table-column>
        <el-table-column label="电话" prop="phone"></el-table-column>
        <el-table-column label="所属单位" prop="unit_name"></el-table-column>
        <el-table-column label="社会商户名" prop="sub_unit_name"></el-table-column>
        <el-table-column label="报名时间">
          <template #default="scope">
            <span> {{ formatDate(scope.row.create_time * 1000) }} </span>
          </template>
        </el-table-column>
      </el-table>
    </page-main>
  </div>
</template>
<script>
export default {
  data() {
    return {
      activity_id: 0,
      dataList: [
        {
          id: 1,
          activity_id: 3, //活动ID
          yj_user_id: 20, //报名的用户ID
          create_time: 1632985748, //报名进间
          user_name: '宋韦良', //报名的人
          phone: '18194858932', //报名的人电话
          unit_name: '杉杉奥特莱斯', //报名人的社会单位名
          sub_unit_name: null //报名人的社会商户名
        }
      ]
    }
  },
  created() {
    this.activity_id = this.$route.query.id - 0
    this.getDataList()
  },
  methods: {
    getDataList() {
      this.$api.post('/unit/Activity/Person', { activity_id: this.activity_id }).then((res) => {
        this.dataList = res.data
      })
    },
    // 时间格式化
    formatDate(timeStamp, format) {
      if (!timeStamp) return ''
      timeStamp = +timeStamp
      var date = new Date(timeStamp)
      // 年月日
      var year = date.getFullYear()
      var month = date.getMonth() + 1
      month = month < 10 ? '0' + month : month
      var day = date.getDate()
      day = day < 10 ? '0' + day : day
      // 时分秒
      var hour = date.getHours()
      hour = hour < 10 ? '0' + hour : hour
      var min = date.getMinutes()
      min = min < 10 ? '0' + min : min
      var sec = date.getSeconds()
      sec = sec < 10 ? '0' + sec : sec
      if (format) {
        format = format.replace('Y', year)
        format = format.replace('M', month)
        format = format.replace('D', day)
        format = format.replace('h', hour)
        format = format.replace('m', min)
        format = format.replace('s', sec)
        return format
      } else {
        return year + '-' + month + '-' + day
      }
    }
  }
}
</script>
